import React from 'react';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import { AuthProvider } from './contexts/AuthContext';
import Navbar from './components/layout/Navbar';
import HomePage from './pages/HomePage';
import LoginPage from './pages/LoginPage';
import RegisterPage from './pages/RegisterPage';
import UserProfilePage from './pages/UserProfilePage';
import AdminUserManagementPage from './pages/AdminUserManagementPage';
import AdminDoctorManagementPage from './pages/AdminDoctorManagementPage';
import AdminDepartmentManagementPage from './pages/AdminDepartmentManagementPage';
import AdminAppointmentManagementPage from './pages/AdminAppointmentManagementPage';
import AuthStatusTestPage from './pages/AuthStatusTestPage';
import AdminDashboardPage from './pages/AdminDashboardPage';
import DoctorDashboardPage from './pages/DoctorDashboardPage';
import ProtectedRoute from './components/common/ProtectedRoute';
import './App.css';

function App() {
  return (
    <AuthProvider>
      <Router>
        <Navbar />
        <ToastContainer position="top-right" autoClose={3000} />
        <div className="container">
          <Routes>
            <Route path="/" element={<HomePage />} />
            <Route path="/login" element={<LoginPage />} />
            <Route path="/register" element={<RegisterPage />} />
            <Route path="/profile" element={
              <ProtectedRoute requiredRole={["ROLE_USER", "ROLE_DOCTOR", "ROLE_ADMIN"]}>
                <UserProfilePage />
              </ProtectedRoute>
            } />
            <Route path="/auth-test" element={<AuthStatusTestPage />} />
            
            {/* 管理员路由 */}
            <Route path="/admin/dashboard" element={
              <ProtectedRoute requiredRole="ROLE_ADMIN">
                <AdminDashboardPage />
              </ProtectedRoute>
            } />
            
            <Route path="/admin/users" element={
              <ProtectedRoute requiredRole="ROLE_ADMIN">
                <AdminUserManagementPage />
              </ProtectedRoute>
            } />
            
            <Route path="/admin/doctors" element={
              <ProtectedRoute requiredRole="ROLE_ADMIN">
                <AdminDoctorManagementPage />
              </ProtectedRoute>
            } />
            
            <Route path="/admin/departments" element={
              <ProtectedRoute requiredRole="ROLE_ADMIN">
                <AdminDepartmentManagementPage />
              </ProtectedRoute>
            } />
            
            <Route path="/admin/appointments" element={
              <ProtectedRoute requiredRole="ROLE_ADMIN">
                <AdminAppointmentManagementPage />
              </ProtectedRoute>
            } />
            
            {/* 医生路由 */}
            <Route path="/doctor/*" element={
              <ProtectedRoute requiredRole="ROLE_DOCTOR">
                <DoctorDashboardPage />
              </ProtectedRoute>
            } />
            
            {/* Add other routes here */}
            {/* <Route path="*" element={<NotFoundPage />} /> */}
          </Routes>
        </div>
      </Router>
    </AuthProvider>
  );
}

export default App; 